package com.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.domain.User;
import com.domain.addAddres;
import com.service.AddresService;
import com.service.Impl.AddresServiceImpl;
import com.service.Impl.UsersServiceImpl;
import com.service.UsersService;

@WebServlet("/AddAddresServlet")
public class AddAddresServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
        //获取域中的用户名
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("username");
        UsersService usersService = new UsersServiceImpl();
        User user = usersService.findByName(name);
        int uid = user.getId();//得到用户ID值
        //获取输入框数据
        String phone = request.getParameter("phone");//获取手机号
        String cmbProvince = request.getParameter("cmbProvince");//获取省份
        String cmbCity = request.getParameter("cmbCity");//获取城市
        String cmbArea = request.getParameter("cmbArea");//获取区域
        String addres = request.getParameter("addres");//获取详细地址

        //封装
        addAddres add = new addAddres();
        add.setUserid(uid);
        add.setAccept("否");
        add.setTelphone(phone);
        add.setProvince(cmbProvince);
        add.setCity(cmbCity);
        add.setArea(cmbArea);
        add.setAddress(addres);
        add.setType("0");

        //传递下一层
        AddresService addresService = new AddresServiceImpl();
        addresService.addAdres(add);
        //重定向到当前页面
        response.sendRedirect("/woniusales/page/vipPage.jsp");

    }
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
